function net_test()
	local server = network.create_node()
	local client = network.create_node()

	client:auto_send_packets(false)

	-- Generate messages
	local messages = {}
	--local message_count = 1024
	--local message_count = 4096
	local message_count = 10000
	
	for i=1,message_count do
		local len = math.random(4, 10)
		--local len = 10

		local msg = {}
		for j=1,len do
			msg[j] = math.random(0, 10000000)
		end

		messages[i] = msg
	end
	
	local cur_message = 1

	function server:message(bs)
		if bs.getfirst() == 0 then
			return
		end

		repeat
			-- Check message
			local msg = messages[cur_message]

			if bit.band(cur_message, 0xffff) == 0 then
				print(cur_message)
			end
			for j=1,#msg do

				local actual = bs.int()
				local expected = msg[j]

				if actual ~= expected then
					error("Error at msg " .. cur_message .. ", int " .. j .. " out of " .. #msg .. ": expected " .. expected .. ", was " .. actual)
				end
			end

			cur_message = cur_message + 1
		until bs.getnext() == 0
	end

	function client:message(bs)
	end

	server:host(31337)
	local server_link = client:connect("localhost", 31337)

	print("Hosting")

	-- Send messages

	local server_out = client:out_stream(server_link)

	local cur_send = 1

	--[[
	for i=1,message_count do
		local msg = messages[i]
		for j=1,#msg do
			server_out.int(msg[j])
		end
		server_out.putend()
	end]]

	repeat
		if cur_send <= message_count then
			local msg = messages[cur_send]
			for j=1,#msg do
				server_out.int(msg[j])
			end
			server_out.putend()
			cur_send = cur_send + 1
		end

		if math.random() < 0.05 then
			client:send_packet_all()
		end

		server:update()
		client:update()
	until cur_message > message_count
end